//#pragma once

#ifndef __MAYMAP_H__
#define __MAYMAP_H__

#include "RBTree.h"

namespace yyp
{
	template<class K, class V>
	class map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};

	public:
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::Iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::ConstIterator const_iterator;
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::ReverseIterator reverse_iterator;
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::ConstReverseIterator const_reverse_iterator;

		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}

		const_iterator cbegin() const
		{
			return _t.Begin();
		}

		const_iterator cend() const
		{
			return _t.End();
		}

		reverse_iterator rbegin()
		{
			return _t.RBegin();
		}

		reverse_iterator rend()
		{
			return _t.REnd();
		}

		const_reverse_iterator crbegin() const
		{
			return _t.RBegin();
		}

		const_reverse_iterator crend() const
		{
			return _t.REnd();
		}

		V& operator[](const K& key)
		{
			return ((insert({ key, V() })).first)->second;
		}

		pair<iterator, bool> insert(const pair<K, V>& kv)
		{
			return _t.Insert(kv);
		}

		iterator find(const K& key)
		{
			return _t.Find(key);
		}

	private:
		RBTree<K, pair<const K, V>, MapKeyOfT> _t;
	};
}

#endif
